package com.tjetc.service.impl;

import com.tjetc.entity.ShoePhotos;
import com.tjetc.entity.ShoesInquirys;
import com.tjetc.dao.ShoesInquirysDao;
import com.tjetc.service.ShoesInquirysService;
import com.tjetc.util.Pager;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 商品咨询表(ShoesInquirys)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:06:07
 */
@Service("shoesInquirysService")
public class ShoesInquirysServiceImpl implements ShoesInquirysService {
    @Resource
    private ShoesInquirysDao shoesInquirysDao;

    /**
     * 通过ID查询单条数据
     *
     * @param sqid 主键
     * @return 实例对象
     */
    @Override
    public ShoesInquirys queryById(Long sqid) {
        return this.shoesInquirysDao.queryById(sqid);
    }

    /**
     * 分页查询
     *
     * @param shoesInquirys 筛选条件
      分页对象
     * @return 查询结果
     */
    @Override
    public Object queryByPage(ShoesInquirys shoesInquirys, Integer pageNum,Integer pageSize) {
        //查询总记录条数
        Integer recordCount = shoesInquirysDao.count(shoesInquirys);
        //构建分页信息对象
        Pager pager = new Pager(pageNum, pageSize, recordCount);
        //根据pager查询需要的数据
        List<ShoesInquirys> list = shoesInquirysDao.queryAllByLimit(shoesInquirys,pager.getStart(), pageSize);
        //将分页信息和查询到的数据一起返回到前端
        HashMap<String,Object> map = new HashMap<>();
        map.put("pager",pager);
        map.put("list",list);
        return map;
    }

    /**
     * 新增数据
     *
     * @param shoesInquirys 实例对象
     * @return 实例对象
     */
    @Override
    public ShoesInquirys insert(ShoesInquirys shoesInquirys) {
        this.shoesInquirysDao.insert(shoesInquirys);
        return shoesInquirys;
    }

    /**
     * 修改数据
     *
     * @param shoesInquirys 实例对象
     * @return 实例对象
     */
    @Override
    public ShoesInquirys update(ShoesInquirys shoesInquirys) {
        this.shoesInquirysDao.update(shoesInquirys);
        return this.queryById(shoesInquirys.getSqid());
    }

    /**
     * 通过主键删除数据
     *
     * @param sqid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long sqid) {
        return this.shoesInquirysDao.deleteById(sqid) > 0;
    }
}
